package com.group4.xiao_ge_lai_yi_zhu.controller.register_controller;

import com.group4.xiao_ge_lai_yi_zhu.domain.User;
import com.group4.xiao_ge_lai_yi_zhu.service.RegisterService;

import java.util.Scanner;

/**
 * 注册页面
 * 用于注册新用户
 */
public class RegisterPage {
    private RegisterService registerService = new RegisterService();
    String username;
    String password;

    public void register() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入用户名:");
            username = sc.nextLine();
            boolean exist = registerService.usernameExist(username);
            if (!exist) {
                System.out.println("用户名已存在,请重新注册");
            } else {
                break;
            }
        }
        while (true) {
            System.out.println("请输入密码:");
            password = sc.nextLine();
            if(password.equals("")){
                System.out.println("密码不能为空,请重新输入");
            }else {
                break;
            }
        }
        User user = new User(username, password);
        boolean flag = registerService.userRegister(user);
        if (flag) {
            System.out.println("注册成功");
        }
    }
}
